<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 300px;
            height: 300px;
            margin: 100px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box"></div>

    <script>
        var div = document.querySelector('div')
        div.addEventListener('mousemove', function (e) {
            // console.log(e.pageX);
            // console.log(e.pageY);
            // console.log(div.offsetLeft);

            var x = e.pageX - this.offsetLeft;
            var y = e.pageY - this.offsetTop;
            console.log(x)
            console.log(y);;
            div.innerHTML = 'x的坐标是' + x + 'y的坐标是' + y;
        })
    </script>
</body>

</html>